package user;

import java.sql.*;

public class DisplayShoppingCart {
	
	//need to change a lot
	//Temporary assume the user_ID is always 1, only one user
	//The current active order_form is the one that has status 'not cooked yet' which belong to customer 1
	public static String getOrderedFoodInfo(String username) {
		
		DBConnector db = DBConnector.getDBConnector();
		StringBuffer sBuf = new StringBuffer();	
		
		String UserID = LoginValidation.getUserId(username);
		
		String OrderedFoodInfo = "select food_name, order_quantity from contain, food, order_form " +
				"where contain.food_ID = food.food_ID and order_form.form_ID = contain.form_ID and order_form.form_ID = " +
				"(select form_ID from order_form where cus_ID = " + UserID + " and form_state = 'not cooked yet')";
		
		//System.out.println(OrderedFoodInfo);
		
		try {			
			db.prepareStatement(OrderedFoodInfo);
			ResultSet rs = db.queryPstmt();
			sBuf.append("<table border = 0.5 bordercolor = #929292 bgColor=#eeeeee border = 0 width = 120> ");
			if (rs != null && rs.next())
			{
				do{				
					sBuf.append("<tr><td>" +				
							rs.getString(1) + "</td><td>" +
							rs.getString(2) + "</td>" + 
							 "</tr>");	
				}while (rs.next());
			}
			else
			{
				sBuf.append("<tr><td>No selection</td></tr>");
			}
			sBuf.append("</table>");
			
			return sBuf.toString();
		}catch (SQLException ex){
			ex.printStackTrace();
			System.out.println("DisplayShoppingCart.java Exception");
			return "";
		}finally{
			// TODO to be implemented later
		}
	}
}
